package Files;

import java.io.*;

public class Demo1 {
    public static void main(String[] args) {
        Person[] person = new Person[]{new Person("james","36","male"),
                new Person("KD","30","male"),
                new Person("klyle","27","male")};
        File file = new File("person.txt");
        FileOutputStream fos;
        try {
            fos = new FileOutputStream(file);
            DataOutputStream dos = new DataOutputStream(fos);

            for (Person value : person) {
                dos.writeUTF(value.name);
                dos.writeUTF(value.age);
                dos.writeUTF(value.sex);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    static class Person{
        private String name;
        private String age;
        private String sex;

        public Person(String name,String age,String sex) {
            this.name = name;
            this.age = age;
            this.sex = sex;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAge() {
            return age;
        }

        public void setAge(String age) {
            this.age = age;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }
    }

}
